﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CI;
using System.Data.SqlClient;
using System.Data;
using CI.Caja.BE;

namespace CI.Caja.DL
{
    public class DA_OrdenDetalle
    {
        DA_Utilitario objUtility = new DA_Utilitario();
        public List<BE_OrdenDetalle> ObtenerOrdenDetalle(BE_Orden prmOrdenBE)
        {
            SqlConnection cnx = new SqlConnection(DA_Utilitario.ObtenerConexion());
            try
            {
                cnx.Open();
                SqlCommand cmd = new SqlCommand("sp_SEL_ORDENDETALLE", cnx);
                cmd.CommandType = CommandType.StoredProcedure;

                var _with1 = (cmd.Parameters);
                _with1.Add("@NroOrden", SqlDbType.VarChar).Value = prmOrdenBE.NroOrden;

                SqlDataReader reader = default(SqlDataReader);

                reader = cmd.ExecuteReader();

                List<BE_OrdenDetalle> objListadoOrdenDetalleBE = new List<BE_OrdenDetalle>();

                while (reader.Read())
                {
                    BE_OrdenDetalle objOrdenDetalleBE = new BE_OrdenDetalle();

                    objOrdenDetalleBE.NroOrden = reader.GetString(reader.GetOrdinal("NroOrden"));
                    objOrdenDetalleBE.Item = reader.GetString(reader.GetOrdinal("Item"));
                    objOrdenDetalleBE.IdServicio = reader.GetString(reader.GetOrdinal("IdServicio"));
                    objOrdenDetalleBE.Descripcion = reader.GetString(reader.GetOrdinal("txtDescripcion"));
                    objOrdenDetalleBE.Precio = reader.GetDecimal(reader.GetOrdinal("numPrecio"));
                    objOrdenDetalleBE.Cantidad = reader.GetInt32(reader.GetOrdinal("numCantidad"));
                    objOrdenDetalleBE.SubTotal = reader.GetDecimal(reader.GetOrdinal("numSubTotal"));
                    objOrdenDetalleBE.MontoDeducible = reader.GetDecimal(reader.GetOrdinal("numMontoDeducible"));
                    objOrdenDetalleBE.Total = reader.GetDecimal(reader.GetOrdinal("numTotal"));

                    objListadoOrdenDetalleBE.Add(objOrdenDetalleBE);
                }

                return objListadoOrdenDetalleBE;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                cnx.Close();
            }
        }
    }
}
